Unit 6 Activity: Agent Dialogue with KQML and KIF

Activity Overview

This activity demonstrates agent-to-agent communication using KQML (Knowledge Query and Manipulation Language) and KIF (Knowledge Interchange Format).

Scenario: Alice (procurement agent) queries Bob (warehouse stock control agent) about 50-inch television inventory and specifications.

Dialogue Implementation

Message 1: Alice → Bob

Query: Check if 50-inch TVs are in stock

(ask-if
  :sender Alice
  :receiver Bob
  :content (exists ?tv
              (and (television ?tv)
                   (screen-size ?tv 50)
                   (in-stock ?tv)))
  :language KIF
  :ontology warehouse-inventory
  :reply-with query-001)

Explanation: Alice uses ask-if to query whether a statement is true. The content is a KIF expression asking if there exists a television with a 50-inch screen that is in stock.

Message 2: Bob → Alice

Response: Confirm stock availability

(reply
  :sender Bob
  :receiver Alice
  :content (exists ?tv
              (and (television ?tv)
                   (screen-size ?tv 50)
                   (in-stock ?tv)
                   (stock-quantity ?tv 45)))
  :language KIF
  :ontology warehouse-inventory
  :in-reply-to query-001
  :reply-with response-001)

Explanation: Bob confirms that 50-inch TVs are in stock and provides additional information: 45 units available.

Message 3: Alice → Bob

Query: Request information about HDMI specifications

(ask-all
  :sender Alice
  :receiver Bob
  :content (and (television ?tv)
                (screen-size ?tv 50)
                (in-stock ?tv)
                (hdmi-slots ?tv ?slots))
  :language KIF
  :ontology warehouse-inventory
  :reply-with query-002)

Explanation: Alice uses ask-all to retrieve all matching answers for the number of HDMI slots on 50-inch TVs that are in stock.

Message 4: Bob → Alice

Response: Provide HDMI slot information for all matching TVs

(reply
  :sender Bob
  :receiver Alice
  :content (
    (and (television tv-model-sony-x90j)
         (screen-size tv-model-sony-x90j 50)
         (in-stock tv-model-sony-x90j)
         (hdmi-slots tv-model-sony-x90j 4)
         (hdmi-version tv-model-sony-x90j "HDMI 2.1")
         (stock-quantity tv-model-sony-x90j 25))
    (and (television tv-model-samsung-qn50)
         (screen-size tv-model-samsung-qn50 50)
         (in-stock tv-model-samsung-qn50)
         (hdmi-slots tv-model-samsung-qn50 3)
         (hdmi-version tv-model-samsung-qn50 "HDMI 2.0")
         (stock-quantity tv-model-samsung-qn50 20)))
  :language KIF
  :ontology warehouse-inventory
  :in-reply-to query-002
  :reply-with response-002)

Explanation: Bob provides detailed information for all 50-inch TVs in stock:

  • Sony X90J: 4 HDMI slots (HDMI 2.1), 25 units
  • Samsung QN50: 3 HDMI slots (HDMI 2.0), 20 units

Message 5: Alice → Bob

Query: Request specific model details

(ask-one
  :sender Alice
  :receiver Bob
  :content (and (television tv-model-sony-x90j)
                (price tv-model-sony-x90j ?price)
                (warranty tv-model-sony-x90j ?warranty))
  :language KIF
  :ontology warehouse-inventory
  :reply-with query-003)

Explanation: Alice uses ask-one to request price and warranty information for the Sony model.

Message 6: Bob → Alice

Response: Provide pricing and warranty information

(reply
  :sender Bob
  :receiver Alice
  :content (and (television tv-model-sony-x90j)
                (price tv-model-sony-x90j 799.99)
                (currency price-usd)
                (warranty tv-model-sony-x90j 24)
                (warranty-unit months))
  :language KIF
  :ontology warehouse-inventory
  :in-reply-to query-003
  :reply-with response-003)

Explanation: Bob provides pricing ($799.99 USD) and warranty (24 months) information. Alice now has complete information to make a procurement decision.

Complete Dialogue Sequence

Alice Bob | | |-----(1) ask-if: 50" TVs in stock?--------------->| | | |<----(2) reply: Yes, 45 units available-----------| | | |-----(3) ask-all: HDMI slots info?--------------->| | | |<----(4) reply: Sony (4 HDMI), Samsung (3 HDMI)---| | | |-----(5) ask-one: Sony price & warranty?--------->| | | |<----(6) reply: $799.99, 24-month warranty--------| | |
← Back to Intelligent Agents Portfolio